Load all required libraries.
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.3 v dplyr 1.0.7
## v tidyr 1.1.3 v stringr 1.4.0
## v readr 2.0.0 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(broom)
Read in raw data from RDS.
raw_data <- readRDS("./year2.RDS")
Make a few small modifications to names and data for visualizations.
final_data <- raw_data %>% mutate(log_copy_per_L = log10(mean_copy_num_L)) %>%
rename(Facility = wrf) %>%
mutate(Facility = recode(Facility,
"NO" = "WRF A",
"MI" = "WRF B",
"CC" = "WRF C"))
Seperate the data by gene target to ease layering in the final plot
#make three data layers
only_positives <<- subset(final_data, (!is.na(final_data$Facility)))
only_n1 <- subset(only_positives, target == "N1")
only_n2 <- subset(only_positives, target == "N2")
only_background <<-final_data %>%
select(c(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke)) %>%
group_by(date) %>% summarise_if(is.numeric, mean)
#specify fun colors
background_color <- "#7570B3"
seven_day_ave_color <- "#E6AB02"
marker_colors <- c("N1" = '#1B9E77',"N2" ='#D95F02')
#remove facilty C for now
#only_n1 <- only_n1[!(only_n1$Facility == "WRF C"),]
#only_n2 <- only_n2[!(only_n2$Facility == "WRF C"),]
only_n1 <- only_n1[!(only_n1$Facility == "WRF A" & only_n1$date == "2020-11-02"), ]
only_n2 <- only_n2[!(only_n2$Facility == "WRF A" & only_n2$date == "2020-11-02"), ]
Build the main plot
#first layer is the background epidemic curve
p1 <- only_background %>%
plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~new_cases_clarke,
type = "bar",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Daily Cases: ', new_cases_clarke),
alpha = 0.5,
name = "Daily Reported Cases",
color = background_color,
colors = background_color,
showlegend = FALSE) %>%
layout(yaxis = list(title = "Clarke County Daily Cases", showline=TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#renders the main plot layer two as seven day moving average
p1 <- p1 %>% plotly::add_trace(x = ~date, y = ~X7_day_ave_clarke,
type = "scatter",
mode = "lines",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Seven-Day Moving Average: ', X7_day_ave_clarke),
name = "Seven Day Moving Average Athens",
line = list(color = seven_day_ave_color),
showlegend = FALSE)
#renders the main plot layer three as positive target hits
p2 <- plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n1,
symbol = ~Facility,
marker = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n2,
symbol = ~Facility,
marker = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(yaxis = list(title = "SARS CoV-2 Copies/L",
showline = TRUE,
type = "log",
dtick = 1,
automargin = TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#adds the limit of detection dashed line
p2 <- p2 %>% plotly::add_segments(x = as.Date("2021-06-30"),
xend = ~max(date + 10),
y = 3571.429, yend = 3571.429,
opacity = 0.35,
line = list(color = "black", dash = "dash")) %>%
layout(annotations = list(x = as.Date("2021-06-30"), y = 3.8, xref = "x", yref = "y",
text = "Limit of Detection", showarrow = FALSE))
p1
p2
Combine the two main plot pieces as a subplot
#seperate n1 and n2 frames by site
#n1
wrf_a_only_n1 <- subset(only_n1, Facility == "WRF A")
wrf_b_only_n1 <- subset(only_n1, Facility == "WRF B")
wrf_c_only_n1 <- subset(only_n1, Facility == "WRF C")
#n2
wrf_a_only_n2 <- subset(only_n2, Facility == "WRF A")
wrf_b_only_n2 <- subset(only_n2, Facility == "WRF B")
wrf_c_only_n2 <- subset(only_n2, Facility == "WRF C")
#rejoin the old data frames then seperate in to averages for each plant.
wrfa_both <- full_join(wrf_a_only_n1, wrf_a_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke", "X7_day_ave_clarke", "Facility", "collection_num", "target", "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "mean_total_copies", "sd_total_copies", "log_copy_per_L")
wrfb_both <- full_join(wrf_b_only_n1, wrf_b_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke", "X7_day_ave_clarke", "Facility", "collection_num", "target", "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "mean_total_copies", "sd_total_copies", "log_copy_per_L")
wrfc_both <- full_join(wrf_c_only_n1, wrf_c_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke", "X7_day_ave_clarke", "Facility", "collection_num", "target", "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "mean_total_copies", "sd_total_copies", "log_copy_per_L")
#get max date
maxdate <- max(wrfa_both$date)
mindate <- min(wrfa_both$date)
Build loess smoothing figures figures
This makes the individual plots
#**************************************WRF A PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_botha <- ggplot(wrfa_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_botha<<-..y..), method = "loess", color = '#1B9E77',
span = 0.3, n = 253)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_botha
## `geom_smooth()` using formula 'y ~ x'
fit_botha
## [1] 11.53689 11.57461 11.61204 11.64917 11.68601 11.72255 11.75880 11.79475
## [9] 11.83041 11.86579 11.90087 11.93567 11.97019 12.00438 12.03825 12.07181
## [17] 12.10508 12.13808 12.17083 12.20336 12.23567 12.26775 12.29959 12.33117
## [25] 12.36248 12.39351 12.42424 12.45466 12.48475 12.51451 12.54391 12.57294
## [33] 12.60159 12.62985 12.65860 12.68845 12.71892 12.74954 12.77985 12.80937
## [41] 12.83763 12.86417 12.88851 12.91338 12.94085 12.96941 12.99759 13.02390
## [49] 13.04685 13.06495 13.08024 13.09556 13.11061 13.12510 13.13876 13.15130
## [57] 13.16243 13.17186 13.17931 13.18450 13.18713 13.18693 13.18360 13.17686
## [65] 13.16544 13.14876 13.12758 13.10265 13.07472 13.04454 13.01288 12.98048
## [73] 12.94811 12.91651 12.88643 12.85864 12.82810 12.79097 12.74983 12.70724
## [81] 12.66576 12.62797 12.59641 12.56830 12.53934 12.50982 12.48003 12.45025
## [89] 12.42078 12.39191 12.36392 12.33712 12.31179 12.28822 12.26670 12.24753
## [97] 12.23098 12.21715 12.20573 12.19648 12.18912 12.18341 12.17907 12.17586
## [105] 12.17351 12.17176 12.17035 12.16903 12.16753 12.16559 12.16295 12.16011
## [113] 12.15774 12.15584 12.15442 12.15350 12.15308 12.15316 12.15378 12.15492
## [121] 12.15660 12.15883 12.16162 12.16498 12.16891 12.17395 12.18037 12.18782
## [129] 12.19596 12.20445 12.21293 12.22105 12.22848 12.23485 12.24334 12.25611
## [137] 12.27135 12.28723 12.30191 12.31359 12.32042 12.32269 12.32217 12.31923
## [145] 12.31428 12.30769 12.29986 12.29118 12.28203 12.27281 12.26389 12.25568
## [153] 12.24857 12.24293 12.23916 12.23764 12.23878 12.24295 12.25054 12.26195
## [161] 12.27715 12.29560 12.31687 12.34058 12.36632 12.39367 12.42224 12.45162
## [169] 12.48141 12.51120 12.54058 12.56916 12.59652 12.62225 12.64923 12.68018
## [177] 12.71451 12.75163 12.79094 12.83185 12.87377 12.91611 12.95827 12.99966
## [185] 13.03970 13.07778 13.11331 13.14571 13.17438 13.19873 13.21816 13.23208
## [193] 13.23990 13.24103 13.23488 13.21941 13.19431 13.16157 13.12319 13.08114
## [201] 13.03742 12.99402 12.95292 12.91611 12.87692 12.82935 12.77638 12.72099
## [209] 12.66617 12.61490 12.57016 12.52881 12.48591 12.44177 12.39669 12.35099
## [217] 12.30497 12.25894 12.21320 12.16805 12.12382 12.08080 12.03930 11.99963
## [225] 11.96209 11.92598 11.89040 11.85538 11.82098 11.78723 11.75416 11.72182
## [233] 11.69024 11.65947 11.62954 11.60050 11.57238 11.54522 11.51907 11.49384
## [241] 11.46944 11.44588 11.42314 11.40123 11.38013 11.35986 11.34041 11.32176
## [249] 11.30393 11.28691 11.27069 11.25528 11.24067
#assign fits to a vector
both_trenda <- fit_botha
#extract y min and max for each
limits_botha <- ggplot_build(extract_botha)$data
## `geom_smooth()` using formula 'y ~ x'
limits_botha <- as.data.frame(limits_botha)
both_ymina <- limits_botha$ymin
both_ymaxa <- limits_botha$ymax
#reassign dataframes (just to be safe)
work_botha <- wrfa_both
#fill in missing dates to smooth fits
work_botha <- work_botha %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_botha <- work_botha$date
#create a new smooth dataframe to layer
smooth_frame_botha <- data.frame(date_vec_botha, both_trenda, both_ymina, both_ymaxa)
#WRF A
#plot smooth frames
p_wrf_a <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_botha, y = ~both_trenda,
data = smooth_frame_botha,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha,
'</br> Median Log Copies: ', round(both_trenda, digits = 2)),
line = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_botha, ymin = ~both_ymina, ymax = ~both_ymaxa,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxa, digits = 2),
'</br> Min Log Copies: ', round(both_ymina, digits = 2)),
name = "",
fillcolor = '#1B9E77',
line = list(color = '#1B9E77')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF A") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfa_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#1B9E77', size = 6, opacity = 0.65))
p_wrf_a
save(p_wrf_a, file = "./site_objects/wrf_a_year2.rda")
#**************************************WRF B PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothb <- ggplot(wrfb_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothb<<-..y..), method = "loess", color = '#D95F02',
span = 0.3, n = 253)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothb
## `geom_smooth()` using formula 'y ~ x'
fit_bothb
## [1] 10.70096 10.79560 10.88827 10.97895 11.06765 11.15434 11.23902 11.32168
## [9] 11.40231 11.48091 11.55746 11.63195 11.70438 11.77471 11.84294 11.90911
## [17] 11.97325 12.03539 12.09557 12.15383 12.20993 12.26368 12.31514 12.36439
## [25] 12.41150 12.45654 12.49959 12.54072 12.58001 12.61752 12.65334 12.68752
## [33] 12.72015 12.75131 12.78026 12.80645 12.83020 12.85183 12.87165 12.88998
## [41] 12.90713 12.92343 12.93918 12.95223 12.96100 12.96662 12.97025 12.97304
## [49] 12.97614 12.98071 12.98535 12.98804 12.98903 12.98853 12.98678 12.98402
## [57] 12.98047 12.97637 12.97194 12.96742 12.96303 12.95902 12.95561 12.95303
## [65] 12.95097 12.94888 12.94666 12.94419 12.94136 12.93805 12.93415 12.92955
## [73] 12.92414 12.91779 12.91041 12.90187 12.89328 12.88545 12.87781 12.86976
## [81] 12.86075 12.85017 12.83747 12.82300 12.80757 12.79125 12.77412 12.75626
## [89] 12.73774 12.71864 12.69904 12.67901 12.65864 12.63799 12.61714 12.59618
## [97] 12.57517 12.55299 12.52861 12.50231 12.47435 12.44499 12.41451 12.38317
## [105] 12.35123 12.31896 12.28663 12.25450 12.22284 12.19191 12.16198 12.13000
## [113] 12.09346 12.05346 12.01109 11.96744 11.92362 11.88071 11.83981 11.80202
## [121] 11.76842 11.74012 11.71821 11.70379 11.69794 11.69953 11.70613 11.71687
## [129] 11.73090 11.74734 11.76535 11.78405 11.80259 11.82010 11.84415 11.87996
## [137] 11.92321 11.96955 12.01466 12.05418 12.08379 12.10774 12.13308 12.15964
## [145] 12.18725 12.21575 12.24498 12.27477 12.30495 12.33537 12.36585 12.39624
## [153] 12.42636 12.45605 12.48515 12.51349 12.54091 12.56724 12.59232 12.61598
## [161] 12.63838 12.65985 12.68052 12.70049 12.71989 12.73883 12.75742 12.77578
## [169] 12.79403 12.81229 12.83066 12.84927 12.86822 12.88764 12.90854 12.93161
## [177] 12.95652 12.98292 13.01045 13.03878 13.06756 13.09644 13.12508 13.15314
## [185] 13.18025 13.20609 13.23030 13.25255 13.27247 13.28973 13.30398 13.31487
## [193] 13.32207 13.32522 13.32397 13.31882 13.31068 13.29988 13.28674 13.27159
## [201] 13.25475 13.23653 13.21727 13.19728 13.17570 13.15167 13.12557 13.09779
## [209] 13.06869 13.03865 13.00803 12.97477 12.93692 12.89511 12.84997 12.80211
## [217] 12.75217 12.70077 12.64853 12.59607 12.54402 12.49300 12.44364 12.39655
## [225] 12.35237 12.30902 12.26437 12.21893 12.17323 12.12780 12.08315 12.03980
## [233] 11.99828 11.95912 11.92283 11.88993 11.86095 11.83642 11.81684 11.80108
## [241] 11.78766 11.77659 11.76790 11.76160 11.75770 11.75622 11.75719 11.76061
## [249] 11.76651 11.77490 11.78580 11.79923 11.81520
#assign fits to a vector
both_trendb <- fit_bothb
#extract y min and max for each
limits_bothb <- ggplot_build(extract_bothb)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothb <- as.data.frame(limits_bothb)
both_yminb <- limits_bothb$ymin
both_ymaxb <- limits_bothb$ymax
#reassign dataframes (just to be safe)
work_bothb <- wrfb_both
#fill in missing dates to smooth fits
work_bothb <- work_bothb %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothb <- work_bothb$date
#create a new smooth dataframe to layer
smooth_frame_bothb <- data.frame(date_vec_bothb, both_trendb, both_yminb, both_ymaxb)
#WRF B
#plot smooth frames
p_wrf_b <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothb, y = ~both_trendb,
data = smooth_frame_bothb,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb,
'</br> Median Log Copies: ', round(both_trendb, digits = 2)),
line = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothb, ymin = ~both_yminb, ymax = ~both_ymaxb,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxb, digits = 2),
'</br> Min Log Copies: ', round(both_yminb, digits = 2)),
name = "",
fillcolor = '#D95F02',
line = list(color = '#D95F02')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF B") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfb_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#D95F02', size = 6, opacity = 0.65))
p_wrf_b
save(p_wrf_b, file = "./site_objects/wrf_b_year2.rda")
#**************************************WRF C PLOT********************************************** #add trendlines #extract data from geom_smooth # *********************************span 0.6*********************************** #*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothc <- ggplot(wrfc_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothc<<-..y..), method = "loess", color = '#E7298A',
span = 0.3, n = 253)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothc
## `geom_smooth()` using formula 'y ~ x'
fit_bothc
## [1] 10.80040 10.86898 10.93616 11.00192 11.06623 11.12905 11.19037 11.25015
## [9] 11.30836 11.36498 11.41996 11.47330 11.52495 11.57490 11.62318 11.66991
## [17] 11.71515 11.75901 11.80157 11.84292 11.88225 11.91885 11.95297 11.98485
## [25] 12.01475 12.04292 12.06960 12.09504 12.11949 12.14320 12.16643 12.18941
## [33] 12.21239 12.23563 12.25865 12.28085 12.30232 12.32315 12.34342 12.36322
## [41] 12.38264 12.40176 12.42067 12.44119 12.46424 12.48855 12.51286 12.53590
## [49] 12.55639 12.57307 12.58711 12.60046 12.61304 12.62476 12.63552 12.64525
## [57] 12.65384 12.66121 12.66727 12.67193 12.67510 12.67670 12.67662 12.67479
## [65] 12.67088 12.66479 12.65679 12.64713 12.63605 12.62383 12.61070 12.59692
## [73] 12.58275 12.56844 12.55424 12.54041 12.52540 12.50794 12.48870 12.46835
## [81] 12.44755 12.42698 12.40730 12.38684 12.36382 12.33873 12.31205 12.28427
## [89] 12.25588 12.22737 12.19923 12.17194 12.14600 12.12190 12.10011 12.08114
## [97] 12.06546 12.05247 12.04111 12.03121 12.02259 12.01508 12.00851 12.00270
## [105] 11.99748 11.99267 11.98811 11.98361 11.97901 11.97414 11.96881 11.96414
## [113] 11.96119 11.95969 11.95940 11.96003 11.96135 11.96308 11.96496 11.96674
## [121] 11.96816 11.96895 11.96886 11.96762 11.96498 11.96085 11.95556 11.94943
## [129] 11.94278 11.93593 11.92921 11.92294 11.91743 11.91302 11.90857 11.90297
## [137] 11.89655 11.88967 11.88268 11.87592 11.86974 11.86333 11.85583 11.84750
## [145] 11.83863 11.82947 11.82029 11.81137 11.80297 11.79536 11.78881 11.78358
## [153] 11.77995 11.77819 11.77856 11.78133 11.78677 11.79515 11.80674 11.82180
## [161] 11.84050 11.86252 11.88747 11.91493 11.94451 11.97578 12.00835 12.04181
## [169] 12.07574 12.10975 12.14343 12.17637 12.20816 12.23839 12.26997 12.30570
## [177] 12.34501 12.38733 12.43211 12.47878 12.52679 12.57556 12.62454 12.67316
## [185] 12.72086 12.76708 12.81125 12.85282 12.89122 12.92588 12.95625 12.98176
## [193] 13.00185 13.01595 13.02351 13.02529 13.02279 13.01659 13.00723 12.99530
## [201] 12.98135 12.96595 12.94967 12.93305 12.91351 12.88893 12.86061 12.82988
## [209] 12.79804 12.76639 12.73627 12.70413 12.66620 12.62336 12.57648 12.52647
## [217] 12.47421 12.42058 12.36648 12.31279 12.26039 12.21018 12.16304 12.11986
## [225] 12.08153 12.04550 12.00895 11.97234 11.93614 11.90079 11.86676 11.83452
## [233] 11.80452 11.77721 11.75307 11.73256 11.71612 11.70423 11.69734 11.69446
## [241] 11.69431 11.69688 11.70221 11.71030 11.72116 11.73481 11.75125 11.77050
## [249] 11.79258 11.81749 11.84525 11.87588 11.90937
#assign fits to a vector
both_trendc <- fit_bothc
#extract y min and max for each
limits_bothc <- ggplot_build(extract_bothc)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothc <- as.data.frame(limits_bothc)
both_yminc <- limits_bothc$ymin
both_ymaxc <- limits_bothc$ymax
#reassign dataframes (just to be safe)
work_bothc <- wrfc_both
#fill in missing dates to smooth fits
work_bothc <- work_bothc %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothc <- work_bothc$date
#create a new smooth dataframe to layer
smooth_frame_bothc <- data.frame(date_vec_bothc, both_trendc, both_yminc, both_ymaxc)
#WRF C
#plot smooth frames
p_wrf_c <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothc, y = ~both_trendc,
data = smooth_frame_bothc,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc,
'</br> Median Log Copies: ', round(both_trendc, digits = 2)),
line = list(color = '#E7298A', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothc, ymin = ~both_yminc, ymax = ~both_ymaxc,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxc, digits = 2),
'</br> Min Log Copies: ', round(both_yminc, digits = 2)),
name = "",
fillcolor = '#E7298A',
line = list(color = '#E7298A')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF C") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfc_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#E7298A', size = 6, opacity = 0.65))
p_wrf_c
save(p_wrf_c, file = "./site_objects/wrf_c_year2.rda")
keeping in case
#save(wrfa_both, file = "./plotly_objs/wrfa_both.rda")
#save(wrfb_both, file = "./plotly_objs/wrfb_both.rda")
#save(wrfc_both, file = "./plotly_objs/wrfc_both.rda")
#save(date_vec_botha, file = "./plotly_objs/date_vec_botha.rda")
#save(date_vec_bothb, file = "./plotly_objs/date_vec_bothb.rda")
#save(date_vec_bothc, file = "./plotly_objs/date_vec_bothc.rda")
#save(both_ymina, file = "./plotly_objs/both_ymina.rda")
#save(both_ymaxa, file = "./plotly_objs/both_ymaxa.rda")
#save(both_yminb, file = "./plotly_objs/both_yminb.rda")
#save(both_ymaxb, file = "./plotly_objs/both_ymaxb.rda")
#save(both_yminc, file = "./plotly_objs/both_yminc.rda")
#save(both_ymaxc, file = "./plotly_objs/both_ymaxc.rda")